<?php
/**
 * Created by PhpStorm.
 * User: divya
 * Date: 2018/6/29
 * Time: 下午2:56
 */
$conn = mysqli_connect('localhost',"root","root") or die('connect faild'.mysqli_error());

// 防止中文乱码
//mysqli_query($conn,'SEL NAMES UTF8');

// 选择数据库
mysqli_select_db($conn,"ShowDB")or die('select faild'.mysqli_error());

//获取get  参数
$cityname = $_GET['city'];
$type = $_GET['type'];
$page = $_GET['page'];
$showid = $_GET['showid'];
$pagesize = 3;
// 执行sql语句
$sql = "
select t_show.show_id,t_show.show_title,`show_image`,`show_time`,t_show.show_desc,t_place.place_name from t_show,t_place where t_show.place_id = t_place.place_id and
t_show.show_id='$showid'";
// 添加分页功能
//$offset = ($page - 1)*$pagesize;
//$sql = $sql." limit $offset,$pagesize";
$result = mysqli_query($conn,$sql);
// 获取执行结果
$array = array();
while ($row = mysqli_fetch_array($result)){
    $array['show_id'] = $row["show_id"];
    $array['show_title'] = $row['show_title'];
    $array['show_image'] = $row["show_image"];
    $array['show_time'] = $row['show_time'];
    $array['show_desc'] = $row["show_desc"];
    $array['show_title'] = $row['show_title'];
    $array['place_name'] = $row["place_name"];
}
// 增加评论功能，获取当前演出的评论数据
$sql = "select * from t_comment where show_id= $showid";
$result = mysqli_query($conn,$sql);
// 进行数据拼接
$i = 0;
$commentList = $array['commentList'];
while ($row = mysqli_fetch_array($result)){
    $commentList[$i]['comment_stage'] = $row['comment_stage'];
    $commentList[$i]['comment_content'] = $row['comment_content'];
    $commentList[$i]['comment_time'] = $row['comment_time'];
    $commentList[$i]['user_id'] = $row['user_id'];
    $i ++;
}
$array['commentList'] = $commentList;
// 关闭数据库
mysqli_close($conn);
// 返回json
$json = json_encode(array(
    'resultCode'=>200,
    "message"=>'success!',
    'data'=>$array
),JSON_UNESCAPED_UNICODE);
echo ($json);